package P1900;

import java.util.Scanner;

/**
 * @author: zhouyang
 * @descrpition: 经典问题 问1-n范围内的数里 k这个数字出现了多少次
 *
 * @time: 2019-10-07 15:34
 */
public class P1980_计数问题_ {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        scanner.close();
        invoke(n,k);
    }

    private static void invoke(int n, int k) {
        int floor = 1,res = 0;
        while(floor <= n){//floor是这个数第floor位为k有多少种合法选择
            int left = n/(floor*10),mid=n/floor%10,right=n%floor;//把n分为三部分
            if(k != 0){
                if(mid > k){
                    res += (left+1)*floor;
                }
                else if(mid == k){
                    res += left*floor+right+1;
                }else{
                    res += left*floor;
                }
            }else{
                if(mid != 0){
                    res += left*floor;
                }else{
                    res += (left-1)*floor+right+1;
                }
            }
            floor *= 10;
        }
        System.out.println(res);
    }
}
